package com.itheima.test4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {
        //创建线程池
        ThreadPoolExecutor pool = new ThreadPoolExecutor(
                3,
                6,
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(2),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        //接收客户端上传的文件
        //创建ServerSocket对象并指定端口号
        ServerSocket ss = new ServerSocket(8888);
        while (true) {
            //等待客户端连接并返回Socket对象
            Socket socket = ss.accept();
            /*//创建线程对象并启动线程
            new MyThread(socket).start();*/
            //创建线程对象(任务）并提交到线程池
            pool.submit(new MyRunnable(socket));
        }
    }
}
